package com.situ.mall.admin.config;

import com.situ.mall.admin.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author yangkx
 * @create 2023-09-11-14:36
 */
//配置类
//介入SpringMVC的配置
@Configuration
public class MyWebMVCConfig implements WebMvcConfigurer {

    //添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())//new一个拦截器的对象
                .addPathPatterns("/**")//需要拦住哪些地址
                .excludePathPatterns("/login","/u/**","/css/**","/js/**","/lib/**","/images/**");//需要忽略哪些地址
    }

    //添加资源处理器（上传文件）
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/u/**")//浏览器只要发这个请求，就去下面指定的地址里找
                .addResourceLocations("file:D:\\UserAttachment\\");//file:+电脑硬盘中的实际地址 上传文件的文件夹的目录
    }

}
